var o = function (o) {
  return o && o.__esModule ? o : {
    default: o
  };
}(require("../../../../utils/toot.js"));
var bmap = require('../../../../utils/bmap-wx.min.js');
var app = getApp();
var page
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //星期
    weekdex: 0,
    pinyin: "",
    ismore: true,
    list: [],
    itemList: [],
    page: 0,
    pagesize: 10,

    hid: "",
    long: "", //远程挂号
    inquiry: 0, //0 图文  1 视频   2 电话   3 开药  8 手术
    needFix: false,
    bannerHeight: 0,
    searchCont: "",
    openmore: false,
    tabdex: "",
    popshow: false,
    keshi_two: "",
    ser_key: "",
    order: "",
    zhicheng: "",
    zongheList: [{
      items: "综合排序",
      checked: false
    },
    {
      items: "回答次数",
      checked: false
    },
    {
      items: "星级评分",
      checked: false
    },
    {
      items: "响应时间",
      checked: false
    },

    ],
    shaixuanList: [{
      items: "价格区间",
    },
    {
      items: "医生职称",
    },
    ],
    jiage: [],
    keyword: "",
    biaoqian: "",
    shequlist: [],
    shequdex: 0,
    typs: ""
  },
  //选择日期
  weekitem(e) {
    this.setData({
      weekdex: e.currentTarget.dataset.dex
    })
  },
  typesclick1(e) {
    let datas = this.data;
    var that = this
    let i = e.currentTarget.dataset.index
    let dex = e.currentTarget.dataset.dex
    var section2 = that.data.section2
    datas.section2.map(function (item) {
      item.checked = false
    })
    datas.section2[dex].checked = true
    this.setData({
      section2: datas.section2,
      zhicheng: datas.section2[dex].id,

    })
  },
  // 重置
  resultclick() {
    let datas = this.data.shaixuanList;
    for (let i = 0; i < datas.length; i++) {
      let items = datas[i].section;
      for (let j = 0; j < items.length; j++) {
        items[j].checked = false
      }
    }
    this.setData({
      shaixuanList: datas
    })
  },
  // 完成
  submitclick() {
    var that = this
    var keyword = that.data.keyword;
    var order = that.data.order;
    var zhicheng = that.data.zhicheng;
    var biaoqian = that.data.biaoqian;
    that.setData({
      page: 0,
      list: [],
      tabdex: "",
    })
    console.log(that.data.tabdex)
    that.getList(keyword, order, zhicheng, biaoqian)
  },

  getSearch: function (e) {
    this.setData({
      keyword: e.detail.value
    })
  },
  // 执行搜索
  search: function (e) {
    var keyword = this.data.keyword;
    var order = this.data.order;
    var zhicheng = this.data.zhicheng;
    var biaoqian = this.data.biaoqian;
    this.setData({
      page: 0,
      list: []
    })
    this.getList(keyword, order, zhicheng, biaoqian)
  },
  // 隐藏弹框
  hidepop() {
    this.setData({
      popshow: false,
      tabdex: ""
    })
  },
  // tab切换
  tabbtn(e) {
    if (e.currentTarget.dataset.dex === this.data.tabdex) {
      this.setData({
        popshow: false,
        tabdex: "",
      })
    } else {
      this.setData({
        popshow: true,
        tabdex: e.currentTarget.dataset.dex,

      })
    }
  },
  // 综合排序tab选项
  itemchecked(e) {
    var that = this
    let text = e.currentTarget.dataset.text
    var dex = e.currentTarget.dataset.dex
    this.setData({
      page: 0,
      pagesize: 10,
      popshow: false,
      list: [],
      tabdex: "",
      order: dex,
      zongheText: text
    })
    var keyword = that.data.keyword;
    var zhicheng = that.data.zhicheng;
    var biaoqian = that.data.biaoqian;
    that.getList(keyword, dex, zhicheng, biaoqian)
  },


  // 展开收起
  openmore() {
    this.setData({
      openmore: !this.data.openmore
    })
  },
  //解读报告
  readyreport() {
    if (this.data.inquiry == 5) {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?inquiry=5',
      })
      return false
    }
    if (this.data.inquiry == 6) {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?inquiry=6',
      })
      return false
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that = this
    var bgc = wx.getStorageSync('color')
    var tid = options.tid;
    var hid = options.hid;
    var ser_key = options.ser_key;
    var leixing = options.leixing;
    if (hid != undefined && hid != 'undefined') {
      that.setData({
        hid: hid
      })
    }
    if (options.id != undefined && options.id != 'undefined' && ser_key != 'shuhoukangfu') {
      that.setData({
        keshi_two: options.id,
      })
    }
    that.setData({
      tid: tid,
      ser_key: ser_key,
      leixing: leixing,
      title: options.title,
      money: options.money,
      name: options.name
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.getAlldoczhicheng()
    that.getList('', '', '', '');
    that.getksbiaoqian();
  },
  // 查询职称
  getAlldoczhicheng() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.getzhichenglist',
      success: function (res) {
        console.log(res)
        that.setData({
          section2: res.data
        })
      }
    })
  },
  getList: function (keyword, order, zhicheng, biaoqian) {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/green.lists",
      data: {
        keyword: keyword,
        hid: that.data.hid,
        keshi_two: that.data.keshi_two,
        ser_key: that.data.ser_key,
        order: order,
        zhicheng: zhicheng,
        page: that.data.page,
        pagesize: that.data.pagesize,
        biaoqian: biaoqian,
        hid: that.data.hid,
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data),
          page: page
        })

        wx.hideLoading({

        })
      }
    })
  },

  navigator(e) {
    var that = this
    var id = e.currentTarget.dataset.id;
    var zid = e.currentTarget.dataset.zid;
    if (zid == '' || zid == 'undefined' || zid == undefined) {
      zid = '';
    }
    var server = that.data.ser_key
    var money = that.data.money;
    var hid = that.data.hid;
    var name = that.data.name;
    var openid = wx.getStorageSync('openid')
    if (openid == '') {
      wx.navigateTo({
        url: '/hyb_yl/sgin/sgin',
      })
    } else if (server == 'shuhoukangfu') {
      wx.navigateTo({
        url: '/hyb_yl/krecovery/pages/after_operation/after_operation?id=' + that.data.id + "&title=" + name + "&keyword=" + server + "&ser_key=" + server + "&name=" + name + '&c_id=' + id,
      })
    } else if(server == 'yuyuejiuzhen'){
      wx.navigateTo({
        url: '/hyb_yl/userCommunicate/pages/doctor_detail/doctor_detail?did=' + id + "&server=" + server + "&money=" + money + "&hid=" + hid + "&keshi_two=" + that.data.keshi_two + "&tid=" + that.data.tid + "&leixing=" + that.data.leixing + '&name=' + name + '&zid=' + zid,
      })
    }else
    {
      wx.navigateTo({
        url:'/hyb_yl/krecovery/pages/choose_operations/choose_operations?did=' + id + "&server=" + server + "&money=" + money + "&hid=" + hid + "&keshi_two=" + that.data.keshi_two + "&tid=" + that.data.tid + "&leixing=" + that.data.leixing + '&name=' + name + '&zid=' + zid,
      })
    }
  },
  qianyue: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var openid = wx.getStorageSync('openid');
    if (openid == '') {
      wx.navigateTo({
        url: '/hyb_yl/sgin/sgin',
      })
    } else {
      app.util.request({
        'url': "entry/wxapp/green.qianyue",
        data: {
          id: id,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          that.setData({
            page: 0,
            list: [],
          })
          that.getList(that.data.keyword, that.data.order, that.data.zhicheng, that.data.biaoqian)
        }
      })
    }

  },
  quxiao: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var openid = wx.getStorageSync('openid');
    if (openid == '') {
      wx.navigateTo({
        url: '/hyb_yl/sgin/sgin',
      })
    } else {
      app.util.request({
        'url': "entry/wxapp/green.quxiao",
        data: {
          id: id,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          that.setData({
            page: 0,
            list: [],
          })
          that.getList(that.data.keyword, that.data.order, that.data.zhicheng, that.data.biaoqian)
        }
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 社区选择
  shequclick(e) {
    var that = this
    var biaoqian = e.currentTarget.dataset.biaoqian
    var keyword = that.data.keyword;
    var order = that.data.order;
    var zhicheng = that.data.zhicheng;
    this.setData({
      shequdex: e.currentTarget.dataset.dex,
      page: 0,
      list: [],
      biaoqian: biaoqian
    })
    that.getList(keyword, order, zhicheng, biaoqian)
  },
  //查询可是分类标签
  getksbiaoqian() {
    var that = this
    var id = that.data.keshi_two
    app.util.request({
      'url': 'entry/wxapp/index.getksbiaoqian',
      data: {
        id: id,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          shequlist: res.data
        })
      }
    })
  },
  onReachBottom: function () {
    var that = this;
    if (that.data.ismore) {
      wx.showLoading({
        title: '加载中',
      })
      that.getList(that.data.keyword, that.data.order, that.data.zhicheng, that.data.biaoqian);
    }
  },

})